# -*- coding: utf-8 -*-
"""
@Time : 2023/5/20 22:29
@Auth : Junjie Duan
@File : tuyouScript.py
    -i https://pypi.tuna.tsinghua.edu.cn/simple
    https://emojipedia.org/
    https://streamlit-emoji-shortcodes-streamlit-app-gwckff.streamlit.app/

    # 命令汇总 参考
    # https://blog.csdn.net/leonnew/article/details/127963092
"""

import os
import time

import pandas as pd
from PIL import Image
import matplotlib
import matplotlib.pyplot as plt
from cnocr import CnOcr # orc
ocr = CnOcr()
from ultralytics import YOLO
from picColor import PicColor
from basic.ld import Display_ld, KM_ld, Dnconsole

from MyThread import MyThread

# 和 PIL一起用时 需要加这个
matplotlib.use('TkAgg')


class AuToTuYou(Display_ld, KM_ld, PicColor):
    """
        Display_ld: 截图相关
        KM_ld：鼠标键盘相关
        PicColor: 图像识别
    """

    def __init__(self, ld_path=None, index=None, imgs_path=None, thread_name=None):
        """

        :param ld_path:  雷电模拟器文件路径
        :param index:  模拟器序号
        :param imgs_path: 识别图片路径
        """

        super(AuToTuYou, self).__init__()

        self.thread_name = thread_name
        print(f"{self.thread_name}:初始化")
        # app 包名
        self.app_package = "com.tuyoo.fishue4.official"

        self.set_ld_path(ld_path)
        self.set_ldNum(index)

        if imgs_path:
            self.path = imgs_path
        else:
            self.set_imgs_path(os.getcwd())

        self.yolo = YOLO(model="./v8best.pt")
        self.user = {}
        self.drag = None

    def printf(self, mse):
        print(f"{self.thread_name}:{mse}")

    def get_yolo_pos(self, img):
        """
        :param img:
        :return:
        """
        result = self.yolo.predict(img)[0]
        boxes = result.boxes
        if boxes.shape[0] == 0:
            raise RuntimeError("yolo 未检测到关闭框！")

        box = boxes[0]
        box = box.xyxy[0]
        x, y, w, h = box

        # 矩形中心点！
        return x+(w-x), y+(h-y)

    def set_imgs_path(self, path):
        self.path = path

    @staticmethod
    def wait_flag(flag, wait=30):
        """
            状态等待
        :param flag: 判断的函数
        :param wait:  等待时间 单位秒
        :return:
        """
        try_num = 0
        try:
            ret = flag()
        except Exception as e:
            ret = False

        exception_num = 0
        while not ret:
            time.sleep(3)
            if try_num >= wait:
                raise RuntimeError(f'函数（{flag.__name__}）等待超时！')
            try_num += 1
            try:
                ret = flag()
            except Exception as e: pass
            exception_num += 1
            if exception_num >= wait:
                raise RuntimeError(f'（{flag.__name__}）执行异常次数上限')
        return ret

    def plt_show(self, x1=0, y1=0, x2=None, y2=None, img=None, method=None):
        if img is None:
            self.capture(x1=x1, y1=y1, x2=x2, y2=y2)
            img = self.getCVImg()
        if method == 'cv':
            self.imshow(img)
        else:
            plt.imshow(img)
            plt.show()

    def touch(self, x=None, y=None, img=None, method='tz', wait=5):
        """
            触摸 点击
        :param x:
        :param y:
        :param img:
        :param method: tz, template
        :param wait:
        :return:
        """
        if x and y:
            self.moveTo(x, y)
        elif img:
            if method == 'tz':
                func = self.findTzPic
            else:
                func = self.findPic
            x, y = self.wait_flag(lambda: func(pic_name=img), wait=5)
            self.moveTo(x, y)
        else:
            raise RuntimeError('touch is not param！')

        self.leftClick()
        pass

    def tuyoo_app_init(self):
        """
            检查APP安装状态并启动APP
        :return:
        """
        # 判断当前当前模拟器是否运营
        if not self.is_running():
            # 启动模拟器
            self.launch()
            self.wait_flag(self.is_running, wait=120)

        # 重启模拟器并打开途游
        #self.restart("")
        # 是否安装 途游捕鱼
        installed = self.has_install(self.app_package, check_=False)
        if installed:
            # 启动app
            self.invokeapp(self.app_package)
        else:
            self.printf("安装app")
            self.install("TYXXBY-Wechat.apk")
            self.wait_flag(lambda: self.has_install(self.app_package, check_=False), wait=60)
            time.sleep(3)
            self.invokeapp(self.app_package)
        time.sleep(3)
        # 进入游戏启动界面可能存在问题 1. 网络错误， 2.无响应 其他未知

    def register_tuyoo(self, name, id_card):
        """
            首次登录
        :return:
        """
        self.printf('首次登录注册等待。。')

        num = 0
        while True:
            try:
                # 弹出 用户协议
                try:
                    ret = self.wait_flag(lambda: self.findPic(pic_name='0.png', sim=0.80, center=True, drag=True),
                                         wait=1)
                    self.touch(*ret)
                except RuntimeError as e: pass
                try:
                    ret = self.wait_flag(lambda: self.findPic(pic_name='0.2.png', sim=0.80, center=True, drag=True),
                                         wait=1)
                    self.touch(*ret)
                except RuntimeError as e: pass
                try:
                    ret = self.wait_flag(lambda: self.findPic(pic_name='0.1.png', sim=0.80, center=True, drag=True),
                                         wait=1)
                    self.touch(*ret)
                except RuntimeError as e: pass
                #print("检测 小人")
                # 注册授权  我已阅读 775 760， 本机登录（小人） 1015 690
                ret = self.wait_flag(lambda: self.findPic(pic_name='1.png', sim=0.80, center=True), wait=3)
                self.touch(380, 395)
                time.sleep(1)
                self.touch(*ret)
                break
            except RuntimeError as e:
                self.printf(f"第{num}次尝试进入。")
                pass
            if num >= 3*60*5:

                raise RuntimeError('进入游戏失败！')
            num += 1
        self.printf(f"准备登录")
        time.sleep(.5)
        # 姓名550 480, 身份证：550 580 确认： 955 715   变动范围五
        # 姓名280 240, 身份证：280 290 确认： 475 355   变动范围五   最小分辨率
        assert self.wait_flag(lambda: self.findPic(pic_name='2.png', sim=0.90, center=True), wait=30)
        self.touch(280, 240)
        time.sleep(.5)
        #self.keyPressStr('喻志军')
        self.keyPressStr(name)
        time.sleep(2)
        self.touch(280, 290)
        #self.keyPressStr('360502199212300017')
        self.keyPressStr(id_card)
        time.sleep(.5)
        self.touch(475, 355) # 确认身份证

        # 进入游戏界面 480 430 进入游戏
        ret = self.wait_flag(lambda: self.findPic(pic_name='3.png', sim=0.75, center=True, drag=True), wait=60*2)
        self.touch(*ret)

        time.sleep(10)

        return

        # 退出首次登录捕鱼界面  30 100
        ret = self.wait_flag(lambda: self.findPic(pic_name='4.png', sim=0.75, center=True, drag=True), wait=60)
        self.touch(*ret)
        ret = self.wait_flag(lambda: self.findPic(pic_name='5.png', sim=0.75, center=True, drag=True), wait=60)
        self.touch(360, 100) # 退出 360 100
        try:
            ret = self.wait_flag(lambda: self.findPic(pic_name='4.png', sim=0.75, center=True, drag=True), wait=5)
            self.touch(*ret)
            ret = self.wait_flag(lambda: self.findPic(pic_name='5.png', sim=0.75, center=True, drag=True), wait=5)
            self.touch(360, 100)  # 退出 360 100
        except Exception: pass


        time.sleep(8)
        # 首次登录去广告
        #self.close_auto_page()

    def init_and_register_tuyoo(self):

        print("途游初始化")
        self.tuyoo_app_init()
        print("注册并关闭自动弹框")
        self.register_tuyoo()


    def close_auto_page(self):
        # 首次登录去广告

        pngs = [f'{i}x.png' for i in range(6, 12)]
        flag = False
        for i in range(5):

            for png in pngs:
                try:
                    ret = None
                    print(png)
                    ret = self.wait_flag(lambda: self.findPic(pic_name=png, sim=0.80, center=True, drag=True), wait=8)
                    time.sleep(1)
                    self.touch(*ret)
                except RuntimeError as e:
                    try:
                        if i >= 0:  # 当第二次 循环时 每检测一次查看一次 是否进入主界面
                            print("尝试查看主界面")
                            ret = self.wait_flag(lambda: self.findPic(
                                pic_name='12x.png', sim=0.80, center=True, drag=True), wait=8)
                            print(ret)
                            if ret:
                                flag = True
                                break
                    except RuntimeError as e:
                        pass
                    pass
            if flag:
                break
        if not flag:
            raise RuntimeError('首次登录去除广告失败！')

    def cygg(self):

        # 活动-财源滚滚
        # 1.点击活动
        ret = self.wait_flag(lambda: self.findPic(pic_name='13.png', sim=0.80, center=True, drag=True), wait=5)
        self.touch(*ret)
        time.sleep(1)
        # 2.财源滚滚
        ret = self.wait_flag(lambda: self.findPic(pic_name='14.png', sim=0.80, center=True, drag=True), wait=15)
        self.touch(*ret)
        time.sleep(1)
        # 3.去寻宝
        ret = self.wait_flag(lambda: self.findPic(pic_name='15.png', sim=0.80, center=True, drag=True), wait=15)
        self.touch(*ret)
        time.sleep(1)
        # 4.领取标签 加号
        ret = self.wait_flag(lambda: self.findPic(pic_name='16.png', sim=0.75, center=True, drag=True), wait=16)
        self.touch(*ret)
        # 5 领取 可能可以零多个
        num = 0
        while True:
            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='17.png', sim=0.80, center=True, drag=True), wait=6)
                self.touch(*ret)
                self.touch(*ret)
                num+=1
            except RuntimeError as e:
                break
        # 6. 关闭领取
        ret = self.wait_flag(lambda: self.findPic(pic_name='18.png', sim=0.80, center=True, drag=True), wait=6)
        self.touch(*ret)
        # 7. 许愿
        for i in range(num):
            print(i)
            ret = self.wait_flag(lambda: self.findPic(pic_name='19.png', sim=0.80, center=True, drag=True), wait=6)
            self.touch(*ret)
            time.sleep(1)
            self.touch(*ret) # 任意键

        time.sleep(5)
        # 8. 挑战奖励
        ret = self.wait_flag(lambda: self.findPic(pic_name='20.png', sim=0.85, center=True, drag=True), wait=6)
        self.touch(*ret)
        # 领取挑战奖励
        while True:
            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='21.png', sim=0.80, center=True, drag=True), wait=6)
                self.touch(*ret)
                self.touch(*ret) # 任意键
            except RuntimeError as e:
                break
        # 退出 挑战奖励
        ret = self.wait_flag(lambda: self.findPic(pic_name='22.png', sim=0.85, center=True, drag=True), wait=6)
        self.touch(*ret)
        # 退出财源滚滚
        ret = self.wait_flag(lambda: self.findPic(pic_name='23.png', sim=0.85, center=True, drag=True), wait=6)
        self.touch(*ret)
        # 退出活动
        ret = self.wait_flag(lambda: self.findPic(pic_name='23.png', sim=0.85, center=True, drag=True), wait=6)
        self.touch(*ret)

    def week_tuisong(self):

        # 活动-周推送

        # 1.点击活动
        ret = self.wait_flag(lambda: self.findPic(pic_name='13.png', sim=0.80, center=True, drag=True), wait=5)
        self.touch(*ret)
        time.sleep(1)
        # 1.点击
        ret = self.wait_flag(lambda: self.findPic(pic_name='25.png', sim=0.85, center=True, drag=True), wait=6)
        self.touch(*ret)

        # 2.领取
        try:
            ret = self.wait_flag(lambda: self.findPic(pic_name='26.png', sim=0.85, center=True, drag=True), wait=6)
            self.touch(*ret)
            time.sleep(1)
            self.touch(*ret) # 任意键
        except RuntimeError as e:
            # 有可能是已经领了
            pass

        # 退出活动
        ret = self.wait_flag(lambda: self.findPic(pic_name='23.png', sim=0.85, center=True, drag=True), wait=6)
        self.touch(*ret)

    def hd_yxxf(self):
        # 活动-英雄寻访
        # 1.点击活动
        ret = self.wait_flag(lambda: self.findPic(pic_name='13.png', sim=0.90, center=True, drag=True), wait=5)
        self.touch(*ret)
        time.sleep(1)

        # 2。点击英雄寻访
        ret = self.wait_flag(lambda: self.findPic(pic_name='36.png', sim=0.80, center=True, drag=True), wait=5)
        self.touch(*ret)
        # 3.点击寻访
        ret = self.wait_flag(lambda: self.findPic(pic_name='37.png', sim=0.80, center=True, drag=True), wait=5)
        self.touch(*ret)
        # 4.点击寻访礼包
        ret = self.wait_flag(lambda: self.findPic(pic_name='38.png', sim=0.80, center=True, drag=True), wait=5)
        self.touch(*ret)
        time.sleep(.5)
        self.touch(*ret)

        # 5.点击领取寻访
        flag = False
        try:
            ret = self.wait_flag(lambda: self.findPic(pic_name='39.png', sim=0.80, center=True, drag=True), wait=5)
            self.touch(*ret)
            time.sleep(1)
            self.touch(*ret) # 任意键
        except RuntimeError as e: pass

        # 6.退出领取寻访
        ret = self.wait_flag(lambda: self.findPic(pic_name='40.png', sim=0.80, center=True, drag=True), wait=5)
        self.touch(*ret)

        if flag:
            # 7.点击寻访一次
            ret = self.wait_flag(lambda: self.findPic(pic_name='41.png', sim=0.80, center=True, drag=True), wait=5)
            self.touch(*ret)
            time.sleep(1)
            self.touch(*ret) # 任意键

        # 8.退出英雄寻访
        ret = self.wait_flag(lambda: self.findPic(pic_name='42.png', sim=0.80, center=True, drag=True), wait=8)
        self.touch(*ret)

        # 退出活动
        # ret = self.wait_flag(lambda: self.findPic(pic_name='23.png', sim=0.85, center=True, drag=True), wait=6)
        # self.touch(*ret)

    def day_jbp(self):

        # 福利-聚宝盆
        ret = self.wait_flag(lambda: self.findPic(pic_name='27.png', sim=0.85, center=True, drag=True), wait=10)
        self.touch(*ret)
        time.sleep(1)
        # 领取
        try:
            ret = self.wait_flag(lambda: self.findPic(pic_name='28.png', sim=0.70, center=True, drag=True), wait=10)
            self.touch(*ret)
            time.sleep(1)
            self.touch(*ret)  # 任意键
            time.sleep(1)
            # 关闭福利
            ret = self.wait_flag(lambda: self.findPic(pic_name='35.png', sim=0.70, center=True, drag=True), wait=10)
            self.touch(*ret)
        except RuntimeError as e:
            pass

    def fl_kyj(self):
        # 福利-开运金
        ret = self.wait_flag(lambda: self.findPic(pic_name='27.png', sim=0.85, center=True, drag=True), wait=15)
        self.touch(*ret)
        time.sleep(1)
        # 1. 点击开运金
        flag = False
        try:
            ret = self.wait_flag(lambda: self.findPic(pic_name='29.png', sim=0.70, center=True, drag=True), wait=15)
            self.touch(*ret)
            flag = True
        except RuntimeError as e:
            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='30.png', sim=0.70, center=True, drag=True), wait=15)
                self.touch(*ret)
                flag = True
            except RuntimeError as e:

                pass
        if flag:
            # 领取金币
            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='31.png', sim=0.80, center=True, drag=True), wait=15)
                self.touch(*ret)
                time.sleep(1)
                self.touch(*ret) # 任意键
            except RuntimeError as e: pass
            # 幸运筛子


            # 转盘-旋转
            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='32.png', sim=0.70, center=True, drag=True), wait=15)
                self.touch(*ret)
                time.sleep(3)
            except RuntimeError as e: pass

            try:
                # 旋转
                ret = self.wait_flag(lambda: self.findPic(pic_name='33.png', sim=0.70, center=True, drag=True), wait=15)
                self.touch(*ret)
            except RuntimeError as e: pass

            try:
                # 旋转-领取
                ret = self.wait_flag(lambda: self.findPic(pic_name='34.png', sim=0.70, center=True, drag=True), wait=15)
                self.touch(*ret)
            except RuntimeError as e: pass
            # 关闭福利

            ret = self.wait_flag(lambda: self.findPic(pic_name='35.png', sim=0.70, center=True, drag=True), wait=10)
            self.touch(*ret)

    def set_user(self):
        # 读取用户信息
        # 点击角色
        ret = self.wait_flag(lambda: self.findPic(pic_name='43.png', sim=0.85, drag=True), wait=6)
        print(ret)
        self.touch(ret[0] - 5, ret[1])

        # 获取炮台数量
        self.capture(20, 220, 360, 450)
        img = self.getCVImg()
        ocr_ret = ocr.ocr(Image.fromarray(img))
        self.user['炮台'] = ocr_ret[0].get('text') if len(ocr_ret) else None
        # 退出
        ret = self.wait_flag(lambda: self.findPic(pic_name='44.png', sim=0.85, drag=True), wait=6)
        self.touch(*ret)
        time.sleep(1)

        # 获取金币
        self.capture(240, 10, 340, 30)
        img = self.getCVImg()
        ocr_ret = ocr.ocr(Image.fromarray(img))
        self.user['金币'] = ocr_ret[0].get('text') if len(ocr_ret) else None
        # print(ocr_ret)

        # 获取钻石
        self.capture(495, 10, 530, 30)
        img = self.getCVImg()
        ocr_ret = ocr.ocr(Image.fromarray(img))
        self.user['钻石'] = ocr_ret[0].get('text') if len(ocr_ret) else None
        # print(ocr_ret)

    def on_hook(self, sleep=60*10):
        """
            挂机捕鱼
        :return:
        """

        # 进入渔场 巡烈狂杀
        # ret = self.wait_flag(lambda: self.findPic(pic_name='45.png', sim=0.90, center=True, drag=True), wait=20)
        # self.touch(*ret)

        # 判断是否进入渔场
        # ret = self.wait_flag(lambda: self.findPic(pic_name='4.png', sim=0.80, center=True, drag=True), wait=20)
        # self.touch(140, 160)
        num = 0
        while True:

            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='46.png', sim=0.80, center=True, drag=True), wait=20)
                # 完成任务
                self.touch(*ret)
            except RuntimeError as e: pass

            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='47.png', sim=0.70, center=True, drag=True), wait=20)
                # 完成任务
                self.touch(*ret)
            except RuntimeError as e: pass

            try:
                ret = self.wait_flag(lambda: self.findPic(pic_name='47.png', sim=0.70, center=True, drag=True), wait=20)
                # 完成任务
                self.touch(*ret)
            except RuntimeError as e: pass

            if num>=60*10:
                break
            num+=1

    def run(self, register=False):
        print("-  - ")
        if register:
            self.init_and_register_tuyoo()
        else:
            print("启动")
            self.tuyoo_app_init()
            # 进入游戏界面 480 430 进入游戏
            ret = self.wait_flag(lambda: self.findPic(pic_name='3.png', sim=0.95, center=True, drag=True), wait=60 * 5)
            self.touch(*ret)
            time.sleep(8)
            print("去广告")
            self.close_auto_page()

        print("1.每周推送")
        try:
            self.week_tuisong()
        except RuntimeError as e:
            print('周推送失败')
        print("2.聚宝盆")
        try:
            self.day_jbp()
        except RuntimeError as e:
            print('聚宝盆失败')
        print("3.开运金")
        try:
            self.fl_kyj()
        except RuntimeError as e:
            print('开运金失败')
        print("4.财源滚滚")
        try:
            self.cygg()
        except RuntimeError as e:
            print('财源滚滚')

        #print("5.英雄寻访")
        #self.hd_yxxf()

        # 停止app
        #self.plt_show()
        #assert self.stopapp("")

        # 关闭模拟器
        #self.quit()

        pass

    def add_ld(self, index=None, register=False, name=None, id_card=None):
        """
        添加设备会 根据设备id 递增（可能不连续） 如果中途ID被删除 则先填充删除的id，
        :param index:
        :param register:
        :param name:
        :param id_card:
        :return:
        """

        if index is None:
            last_ld = self.get_list()[-1]
            index = last_ld.index+1 if last_ld.index else 0
            self.add_simulator(f'雷电模拟器-{index}')

        self.__init__(
            ld_path=r"E:\leidian\dnmultiplayer.exe",
            index=index,
            imgs_path=r'E:\pythonworkspace\LD\web\auto\imgs',
            thread_name=self.thread_name
        )
        self.drag = False
        self.set_screen_size(960, 540, 160)
        time.sleep(3)

        self.tuyoo_app_init()
        self.set_ldNum(index)
        # self.quit()

        time.sleep(1)
        if register:
            self.register_tuyoo(name=name, id_card=id_card)
            #self.run(register=True)

    def debug(self):

        # ret = self.wait_flag(lambda: self.findPic(pic_name='1.png', sim=0.80, center=True), wait=3)
        # print(ret)
        # print("1.每周推送")
        # self.week_tuisong()
        # # print("2.聚宝盆")
        # # self.day_jbp()
        # print("3.开运金")
        # self.fl_kyj()
        # print("4.财源滚滚")
        # self.cygg()
        # print("5.英雄寻访")
        # self.hd_yxxf()

        self.add_ld()
        pass


class MultiTuYoo(Dnconsole):

    def __init__(self, ld_path, db_path, db_pool=None):
        self.ld_path = ld_path
        self.db_path = db_path
        self.db_pool = db_pool
        self.apk_path = None
        self.images_path = None
        super(MultiTuYoo, self).__init__()
        self.set_ld_path(self.ld_path)

        # 操作类参数
        self.task_conf = pd.DataFrame()
        self.task_infos = pd.DataFrame()
        self.running_device = {}
        self.register_num = 0
        self.register_over_num = 0

    def set_apk_path(self, path):
        self.apk_path = path

    def set_images_path(self, path):
        self.images_path = path

    def add_ld(self):
        """
            这里的 添加雷电只是 添加设备 调整 分辨率 以及安装app
        :return:
        """

        indexs = self.get_list(check_=False)
        if indexs:
            last_index: str = indexs[-1]
            index = int(last_index.index) + 1
        else:
            index = 0

        # 添加设备
        self.add_simulator(f'雷电模拟器-{index}')
        # 设置 编号
        self.set_ldNum(index)
        # 设置尺寸
        self.set_screen_size(960, 540, 160)
        return index

    def start(self):
        """
            启动
        :return:
        """
        keys = list(self.running_device.keys())
        for key in keys:
            self.running_device.get(key).start()
            #print(f"run:{id(self.running_device.get(key))}")
            time.sleep(5)

    def pause(self):
        """ 暂停 """
        keys = list(self.running_device.keys())
        for key in keys:
            self.running_device.get(key).pause()
            time.sleep(3)

    def resume(self):
        """
        恢复
        :return:
        """
        keys = list(self.running_device.keys())
        for key in keys:
            self.running_device.get(key).resume()
            time.sleep(3)

    def stop(self):
        """
        关闭
        :return:
        """
        keys = list(self.running_device.keys())
        for key in keys:
            self.running_device.get(key).stop()
            self.quit(key)
            time.sleep(1)

    def register_polling(self, debug=False, thread_name=None):
        """
            起号模式
             目前阶段，安装app 以及注册 都为内置吧
            1. 添加设备
            2. 安装app
            3. 注册账户
        :return:
        """

        # 添加设备
        index = self.add_ld()
        # 安装app

        at = AuToTuYou(
            ld_path=self.ld_path,
            index=index,
            imgs_path=self.images_path,
            thread_name=thread_name
        )
        print(f"{thread_name}:途游初始化")
        at.tuyoo_app_init()

        # 注册账户
        print(f"{thread_name}:注册并关闭自动弹框")
        rest = at.register_tuyoo(name='喻志军', id_card='360502199212300017')

    def register(self, batch=1, thread_num=5):
        """
            起号模式
        :param batch:
        :param thread_num:
        :return:
        """

        self.register_num = batch
        self.register_over_num = 0

        for key in range(thread_num):
            thread_name = f'模拟器-{key}'

            index = self.add_ld()
            name = '喻志军'
            id_card = '360502199212300017'
            at = AuToTuYou(
                ld_path=self.ld_path,
                index=index,
                imgs_path=self.images_path,
                thread_name=thread_name
            )
            # self.running_device[key] = MyThread(name=name, target=MultiTuYoo.register_polling, args=(self,True, name))
            self.running_device[key] = MyThread(name=thread_name, target=at.add_ld, args=(index, True, name, id_card))
            # print(key, id(self.running_device.get(key)))

        # apk 安装
        # 账号注册
        # 炮台1w倍

    def run_polling(self, debug=False):
        """
            轮询检查任务
        :return:
        """

    def run(self, batch=1):
        """
            batch： 一批多少号
            1. 查询task信息
            2. 是循环轮询
        """
        # conf, task_info  = self.set_task_conf()

        for key in range(batch):

            self.running_device[key] = MyThread(target=self.run_polling, args=(True,))



if __name__ == '__main__':

    mt = MultiTuYoo(
        ld_path=r"E:\leidian\dnmultiplayer.exe",
        db_path='sqlite:///cookies.db',
    )

    mt.register(1, thread_num=1)
    mt.start()

    input()

    at = AuToTuYou(ld_path=r"E:\leidian\dnmultiplayer.exe",
              index=1,
              imgs_path=r'E:\pythonworkspace\LD\web\auto\imgs',)

    # at.plt_show()

    pass